<?php $this->placeholder('container-class')->set('post_ad car')?>
<?php $this->JQuery()->javascriptCaptureStart()?>
jQuery(function() {
    $('#saleby-Dealer').click(function() {
        $('#agentname_label').show();
        $('#agentphone_label').show();
        $('#agentmail_label').show();
        $('#id_input_agent').show();

        $('#ownername_label').hide();
        $('#ownerphone_label').hide();
        $('#ownermail_label').hide();
    });

    $('#saleby-Owner').click(function() {
        $('#agentname_label').hide();
        $('#agentphone_label').hide();
        $('#agentmail_label').hide();
        $('#id_input_agent').hide();

        $('#ownername_label').show();
        $('#ownerphone_label').show();
        $('#ownermail_label').show();
    });

    $('#add_more_btn').click(function() {
        if ($('#add_more_checkbox').attr('value') == 1) {
            $('#add_more_checkbox').attr('value',0);
        }
        else {
            $('#add_more_checkbox').attr('value',1);
        }
        $('#add_more').toggle();
        return false;
    });

    if ($('#add_more_checkbox').attr('value') == 0) {
        $('#add_more').show();
    }
    else {
        $('#add_more').hide();
    }

    // Control for Title
    $('input#title').keydown(function(event) {
        var charLength = 100 - $(this).val().length;
        if (charLength <0) {
            if ( event.keyCode == 8 || event.keyCode == 46 ) {

            } else {
                return false;
            }
        }
        else {
            $('span#counter_title').html('<em>'+charLength + '</em> <?php echo $this->t('characters remaining')?>');
        }
    });

    // Control for Description
    $('textarea#description').keydown(function(event) {
        var charLength = 3000 - $(this).val().length;
        if (charLength <0) {
            if ( event.keyCode == 8 || event.keyCode == 46 ) {

            } else {
                return false;
            }
        }
        else {
            $('span#counter_description').html('<em>'+charLength + '</em> <?php echo $this->t('characters remaining')?>');
        }
    });

    //Online Only Area
    if ($j("#area_l1").val() == "4cbe455a8835c17c10060000") {
        $j("#district_div").hide();
    }
    else {
        $j("#district_div").show();
    }

    $j('#preview_link').click(function() {
        var action = $j('#listing_form').attr('action');
        $j('#listing_form').attr('action', '<?php echo $this->preview_link?>');
        $j('#listing_form').attr('target','_blank');
        $j('#listing_form').submit();
        $j('#listing_form').attr('action', action);
        $j('#listing_form').attr('target','_self');
        return false;
    });
});
<?php $this->JQuery()->javascriptCaptureEnd()?>

<form action="<?php echo $this->escape($this->form->getAction()) ?>" method="<?php echo $this->escape($this->form->getMethod())?>" id="listing_form"  enctype="multipart/form-data">
<fieldset>
          <legend><?php echo $this->t('Create Your Ad');?></legend>
          <div class="required"><?php echo $this->t('Required Information')?></div>
            <div class="category desc">
              <label><?php echo $this->t('Selected Categories')?>
                  <?php /*if (!isset($_GET['id'])):?>
                    (<a href="<?php echo $this->geturl('post-an-ad', 'listing', null, null, array('category' => $_GET['category'], 'change' => 1))?>">Change</a>)
                  <?php endif;*/?>
                  :</label>
              <ul>
                  <?php foreach($this->category as $cat):?>
                      <li>
                          <?php
                            $tmp = array();
                            foreach($cat->getParentTree() as $p) {
                                $tmp[] = $p->name;
                            }
                            echo implode(' &gt; ', $tmp);
                          ?>
                      </li>
                  <?php endforeach;?>
             </ul>
            </div>
            <input type="hidden" name="adid" id="adid" value="<?php echo $this->adid?>">
            <?php foreach($this->category as $cat):?>
                <input type="hidden" name="category[]" value="<?php echo $cat->_id?>">
            <?php endforeach;?>
                
            <div class="title text">
              <label class="required"><?php echo $this->t('Title')?></label>
              <span id="counter_title"><?php echo $this->t('<em>100</em> characters remaining')?></span>
              <?php echo $this->form->title ?>
              <?php if (!empty($_POST['title'])) { ?>
              <?php if (preg_match("#.[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}.#", $_POST['title'])) { ?>
                  <ul class="errors"><li><?php echo $this->t('Please remove email')?></li></ul>
              <?php } } ?>
            </div>

            <div class="custom_info">
                <div class="custom_info_1">                    
                        <div class="nopreviousowners select">
                            <label class="required"><?php echo $this->t('Number of Previous Owners')?></label>
                            <?php echo $this->form->previousowners ?>
                        </div>
                        <div class="area select">
                            <label class="required"><?php echo $this->t('Area')?></label>
                            <?php echo $this->form->area_l1 ?>
                        </div>
                        <div class="district select" id="district_div">
                          <label class="required"><?php echo $this->t('District')?></label>
                            <?php echo $this->form->area_l2 ?>
                        </div>
                        <div class="address textarea">
                            <label><?php echo $this->t('Building Name, Street Address')?></label>
                            <?php echo $this->form->address ?>
                        </div>
                </div>
                <div class="custom_info_2">
                    <div class="make select">
                        <label class="required"><?php echo $this->t('Make')?></label>
                        <?php echo $this->form->make ?>
                    </div>
                    <div class="model select">
                        <label class="required"><?php echo $this->t('Model')?></label>
                        <?php echo $this->form->model ?>
                    </div>
                    <div class="sale_price price text">
                        <span class="required"><?php echo $this->t('Price (Numbers only)')?></span>
                        <label>HKD</label>
                        <label><?php echo $this->form->saleprice ?></label>
                    </div>
                    <div class="capacity price text">
                        <span class="required"><?php echo $this->t('Capacity (Numbers only)')?></span>
                        <label>cc</label>
                        <label><?php echo $this->form->capacity ?></label>
                    </div>
                    <div class="yearmanufactured select">
                        <label class="required"><?php echo $this->t('Year Manufactured')?></label>
                        <?php echo $this->form->yearmanufactured ?>
                    </div>
                    <div class="cartype select">
                        <label class="required"><?php echo $this->t('Car Type')?></label>
                        <?php echo $this->form->cartype ?>
                    </div>
                </div>
             </div>
  
            <div class="property_info_optional">
                <div class="description textarea">
                  <label class="required"><?php echo $this->t('Description')?></label>
                  <span id="counter_description"><?php echo $this->t('<em>3000</em> characters remaining')?></span>
                  <?php echo $this->form->description?>
                  <?php if (!empty($_POST['description'])) { ?>
                  <?php if (preg_match("#.[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}.#", $_POST['description'])) { ?>
                      <ul class="errors"><li><?php echo $this->t('Please remove email')?></li></ul>
                  <?php } } ?>
                  <span id="info_description"><?php echo $this->t('To prevent spam, do not enter any email addresses.')?></span>
                </div>                
            </div>

            <div class="property_info_more button desc" id="add_more_btn">
                <?php echo $this->form->add_more_checkbox?>
                <button id="add_more_btn"><?php echo $this->t('Add More')?></button>
                <p><?php echo $this->t('Click to "Add More" specifications to your Car Info')?></p>
            </div>
          
            <div class="property_info_more optional" id="add_more" style="display:none;">
                    <h1><?php echo $this->t('Key Features')?></h1>
                    <div class="doors radio">
                        <span><?php echo $this->t('Doors')?></span>
                        <?php echo $this->form->doors;?>                        
                    </div>
                    <div class="checkbox">
                        <span><?php echo $this->t('Power Options')?></span>
                        <?php echo $this->form->poweroptions;?>
                    </div>
                    <div class="entertsafety checkbox">
                        <span><?php echo $this->t('Entertainment Features')?></span>
                        <?php echo $this->form->entertcomm;?>
                    </div>
                    <div class="checkbox">
                        <span><?php echo $this->t('Safety Features')?></span>
                        <?php echo $this->form->safetyfeatures;?>
                    </div>
                    <div class="exteriorcolor checkbox">
                        <span><?php echo $this->t('Exterior Color')?></span>
                        <?php echo $this->form->extcolor;?>
                    </div>
                    <div class="interiorcolor checkbox">
                        <span><?php echo $this->t('Interior Color')?></span>
                        <?php echo $this->form->intcolor;?>
                    </div>

                    <h1><?php echo $this->t('Driving &amp; Performances')?></h1>
                    <div class="DriveTypeHorsepower radio">
                        <span><?php echo $this->t('Drive Type')?></span>
                        <?php echo $this->form->drivetype;?>
                    </div>
                    <div class="TransmissionEngine checkbox">
                        <span><?php echo $this->t('Engine')?></span>
                        <?php echo $this->form->engine;?>
                    </div>
                    <div class="mileage1 checkbox">
                        <span><?php echo $this->t('Mileage (km)')?></span>
                        <?php echo $this->form->mileage;?>
                    </div>
                    <div class="radio">
                        <span><?php echo $this->t('Transmission')?></span>
                        <?php echo $this->form->transmission;?>
                    </div>
                    <div class="DriveTypeHorsepower checkbox">
                        <span><?php echo $this->t('Horsepower')?></span>
                        <?php echo $this->form->horsepower;?>
                    </div>
        
                    <h1><?php echo $this->t('Fuel')?></h1>
                    <div class="fueleconomy checkbox">
                        <span><?php echo $this->t('Fuel Economy')?></span>
                        <?php echo $this->form->fueleconomy;?>
                    </div>
                    <div class="fuel checkbox">
                        <span><?php echo $this->t('Fuel')?></span>
                        <?php echo $this->form->fuel;?>
                    </div>

            </div>


            <?php echo $this->Partial('/index/photo-uploader.phtml', 'listing', array('listing' => $this->listing));?>

            <div class="button_em">
              <button><?php echo $this->t('Post Your Ad')?></button>
            </div>
            <p class="preview button">
                <button id="preview_link"><?php echo $this->t('Preview Your Ad')?></button>
            </p>
          </fieldset>

        </form>
